package com.lhn.tankGame4;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * @author lhn
 * @date 2024-07-24 18:05
 */

public class TankGame04 extends JFrame {

    private MyPanel myPanel = null;
    static Scanner scanner = new Scanner(System.in);
    static JButton button1 = new JButton("新游戏");
    static JButton button2 = new JButton("继续游戏");

    public static void main(String[] args) {
        System.out.println("请输入选择：");
        System.out.println("1.新游戏");
        System.out.println("2.继续游戏");

        new TankGame04();
    }

    public TankGame04() {
        String key = scanner.next();

        myPanel = new MyPanel(key);

        //每个100ms重绘一次
        Thread thread = new Thread(myPanel);
        thread.start();

        this.add(myPanel);

        this.setSize(1300, 850);    //方便超出区域观察 setSize包括标题栏？
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
        this.addKeyListener(myPanel);


        //
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("检测到窗口正在关闭...");
                Recorder.saveRecord();
                System.exit(0);
            }
        });
    }
}
